#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<stack>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
int n;
ll h[N];
ll x[N], y[N];
int main()
{
    while (cin >> n, n)
    {
        for (int i = 1; i <= n; i++)
        {
            cin >> h[i];
        }
        stack<ll> as;
        for (int i = 1; i <= n; i++)
        {
            while (as.size() && h[as.top()] >= h[i])
            {
                as.pop();
            }
            if (as.size())
            {
                x[i] = as.top();
            }
            else
            {
                x[i] = 0;
            }
            as.push(i);
        }
        while (as.size()) as.pop();
        for (int i = n; i >= 1; i--)
        {
            while (as.size() && h[as.top()] >= h[i])
            {
                as.pop();
            }
            if (as.size())
            {
                y[i] = as.top();
            }
            else
            {
                y[i] = n + 1;
            }
            as.push(i);
        }
        ll ret = 0;
        for (int i = 1; i <= n; i++)
        {
            ret = max(ret, h[i] * (y[i] - x[i] - 1));
        }
        cout << ret << endl;
    }
    return 0;
}